﻿using System;
using System.Web;
using System.Web.Mvc;
using Kazuku.Core.Models;
using NormActiveRecord;

namespace Kazuku.Core.Controllers {
	public class KazukuController : Controller {
		public KazukuContext Current { get; private set; }

		// A very simple factory that instantiates anything with a default constructor.  Used primarily to replace what are usually 
		//  static methods in an ActiveRecord-like model.  
		//  e.g. Page.GetByID(id), which is very difficult to mock, becomes 
		//  Model.New<Page>().GetByID(id), which is very easy to mock.
		private IModelFactory _model;
		protected IModelFactory Model {
			get { return _model; }
		}

		#region Constructors
		public KazukuController(IModelFactory modelFactory, HttpContextBase httpContext) {
			_model = modelFactory;

			if (httpContext.Items.Contains("KazukuContext")) {
				Current = httpContext.Items["KazukuContext"] as KazukuContext;
			}
		}
		#endregion Constructors
	}
}